package com.ibiaoke.common.utils;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * Created by Administrator on 2017/5/23.
 */
public class OpenTimeUtil {
    /**
     * 验证时间是否在配送范围
     *
     * @param beginTime 开始营业时间
     * @param endTime   结束营业时间
     * @return
     */
    public static boolean validateTime(double beginTime, double endTime) {

        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm");
        String stringDate = simpleDateFormat.format(new Date());
        Double doubleDate = Double.valueOf(stringDate.replace(":", "."));

        if (beginTime < doubleDate && doubleDate < endTime) {
            return true;
        }
        return false;
    }

    public static String getOpenString(Double beginTime, Double endTime) {
        DecimalFormat df = new DecimalFormat("######0.00");
        String begin = df.format(beginTime);
        String end = df.format(endTime);
        return (begin+"-"+end).replace(".",":");
    }


    public static Double getTimeDouble(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        int hour = calendar.get(Calendar.HOUR_OF_DAY);
        int minute = calendar.get(Calendar.MINUTE);
        return Double.parseDouble(hour + "." + minute);
    }
}
